//
//  HZTabBc.swift
//  weibofrist
//
//  Created by 黑眼圈 on 16/4/15.
//  Copyright © 2016年 heiyan. All rights reserved.
//

import UIKit

class HZTabBc: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

   
        //调用添加所有子控制器
        addChildViewController()
        
        //让 tabber的背景透明
        tabBar.shadowImage = UIImage()
        tabBar.backgroundImage = UIImage()
        
        //设置 tabber 的背景图片
         tabBar.shadowImage = UIImage.img()
        tabBar.backgroundImage = UIImage(named:"tabbar_background")
       
    }
    

}


// MARK: - 分类添加子控制器
extension UITabBarController {
    
    
    //创建所有子控制器
    func addChildViewController() {
        
        addChildViewController(HZHomeVc(), imgName: "tabbar_home", seleImgName: "tabbar_home_selected")
        
        addChildViewController(HZMessageVc(), imgName: "tabbar_message_center", seleImgName: "tabbar_message_center_selected")
        
        addChildViewController(HZDiscoverVc(), imgName: "tabbar_discover", seleImgName: "tabbar_discover_selected")
        
        addChildViewController(HZProfileVc(), imgName: "tabbar_profile", seleImgName: "tabbar_profile_selected")
    }
    
    
    
    
    //重载
    func addChildViewController(vc:UIViewController,imgName:String,seleImgName:String) {
        
        //创建子控制器
        vc.title = "首页"
        vc.tabBarItem.image = UIImage(named: imgName)
        
        //让标题栏的图片不被系统渲染
        var img = UIImage(named: seleImgName)
        img = img?.imageWithRenderingMode(.AlwaysOriginal)
        
        vc.tabBarItem.selectedImage = img
        
        //设置标题栏的选中字体的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor(red: 255/255.0, green: 130/255.0, blue: 0, alpha: 1)], forState: .Selected)
        
        //包在导航控制器里去
        let nav = UINavigationController(rootViewController: vc)
        
        //添加
        addChildViewController(nav)
        
    }
    
    
    
}